home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / GNULIB2.C < prev    next >
C/C++ Source or Header  |  1992-03-02  |  17KB  |  886 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3.  
  4. #include "config.h"
  5. #include <stddef.h>
  6.  
  7. #ifndef SItype
  8. #define SItype long int
  9. #endif
  10.  
  11. /* long long ints are pairs of long ints in the order determined by
  12.    WORDS_BIG_ENDIAN.  */
  13.  
  14. #ifdef WORDS_BIG_ENDIAN
  15.   struct longlong {long high, low;};
  16. #else
  17.   struct longlong {long low, high;};
  18. #endif
  19.  
  20. /* We need this union to unpack/pack longlongs, since we don't have
  21.    any arithmetic yet.  Incoming long long parameters are stored
  22.    into the `ll' field, and the unpacked result is read from the struct
  23.    longlong.  */
  24.  
  25. typedef union
  26. {
  27.   struct longlong s;
  28.   long long ll;
  29.   SItype i[2];
  30.   unsigned SItype ui[2];
  31. } long_long;
  32.  
  33. /* Internally, long long ints are strings of unsigned shorts in the
  34.    order determined by BYTES_BIG_ENDIAN.  */
  35.  
  36. #define B 0x10000
  37. #define low16 (B - 1)
  38.  
  39. #ifdef BYTES_BIG_ENDIAN
  40.  
  41. /* Note that HIGH and LOW do not describe the order
  42.    of words in a long long.  They describe the order of words
  43.    in vectors ordered according to the byte order.  */
  44.  
  45. #define HIGH 0
  46. #define LOW 1
  47.  
  48. #define big_end(n)    0 
  49. #define little_end(n)    ((n) - 1)
  50. #define next_msd(i)    ((i) - 1)
  51. #define next_lsd(i)    ((i) + 1)
  52. #define is_not_msd(i,n)    ((i) >= 0)
  53. #define is_not_lsd(i,n)    ((i) < (n))
  54.  
  55. #else
  56.  
  57. #define LOW 0
  58. #define HIGH 1
  59.  
  60. #define big_end(n)    ((n) - 1)
  61. #define little_end(n)    0 
  62. #define next_msd(i)    ((i) + 1)
  63. #define next_lsd(i)    ((i) - 1)
  64. #define is_not_msd(i,n)    ((i) < (n))
  65. #define is_not_lsd(i,n)    ((i) >= 0)
  66.  
  67. #endif
  68.  
  69. /* These algorithms are all straight out of Knuth, vol. 2, sec. 4.3.1. */
  70.  
  71. static int badd ();
  72. static int bsub ();
  73. static void bmul ();
  74. static int bneg ();
  75. static int bshift ();
  76.  
  77. #ifdef L_adddi3
  78. long long 
  79. __adddi3 (u, v)
  80.      long long u, v;
  81. {
  82.   long a[2], b[2], c[2];
  83.   long_long w;
  84.   long_long uu, vv;
  85.  
  86.   uu.ll = u;
  87.   vv.ll = v;
  88.  
  89.   a[HIGH] = uu.s.high;
  90.   a[LOW] = uu.s.low;
  91.   b[HIGH] = vv.s.high;
  92.   b[LOW] = vv.s.low;
  93.  
  94.   badd (a, b, c, sizeof c);
  95.  
  96.   w.s.high = c[HIGH];
  97.   w.s.low = c[LOW];
  98.   return w.ll;
  99. }
  100.  
  101. static int 
  102. badd (a, b, c, n)
  103.      unsigned short *a, *b, *c;
  104.      size_t n;
  105. {
  106.   unsigned long acc;
  107.   int i;
  108.  
  109.   n /= sizeof *c;
  110.  
  111.   acc = 0;
  112.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  113.     {
  114.       /* Widen before adding to avoid loss of high bits.  */
  115.       acc += (unsigned long) a[i] + b[i];
  116.       c[i] = acc & low16;
  117.       acc = acc >> 16;
  118.     }
  119.   return acc;
  120. }
  121. #endif
  122.  
  123. #ifdef L_anddi3
  124. long long 
  125. __anddi3 (u, v)
  126.      long long u, v;
  127. {
  128.   long_long w;
  129.   long_long uu, vv;
  130.  
  131.   uu.ll = u;
  132.   vv.ll = v;
  133.  
  134.   w.s.high = uu.s.high & vv.s.high;
  135.   w.s.low = uu.s.low & vv.s.low;
  136.  
  137.   return w.ll;
  138. }
  139. #endif
  140.  
  141. #ifdef L_iordi3
  142. long long 
  143. __iordi3 (u, v)
  144.      long long u, v;
  145. {
  146.   long_long w;
  147.   long_long uu, vv;
  148.  
  149.   uu.ll = u;
  150.   vv.ll = v;
  151.  
  152.   w.s.high = uu.s.high | vv.s.high;
  153.   w.s.low = uu.s.low | vv.s.low;
  154.  
  155.   return w.ll;
  156. }
  157. #endif
  158.  
  159. #ifdef L_xordi3
  160. long long 
  161. __xordi3 (u, v)
  162.      long long u, v;
  163. {
  164.   long_long w;
  165.   long_long uu, vv;
  166.  
  167.   uu.ll = u;
  168.   vv.ll = v;
  169.  
  170.   w.s.high = uu.s.high ^ vv.s.high;
  171.   w.s.low = uu.s.low ^ vv.s.low;
  172.  
  173.   return w.ll;
  174. }
  175. #endif
  176.  
  177. #ifdef L_one_cmpldi2
  178. long long
  179. __one_cmpldi2 (u)
  180.      long long u;
  181. {
  182.   long_long w;
  183.   long_long uu;
  184.  
  185.   uu.ll = u;
  186.  
  187.   w.s.high = ~uu.s.high;
  188.   w.s.low = ~uu.s.low;
  189.  
  190.   return w.ll;
  191. }
  192. #endif
  193.  
  194. #ifdef L_lshldi3
  195. long long
  196. __lshldi3 (u, b1)
  197.      long long u;
  198.      long long b1;
  199. {
  200.   long_long w;
  201.   unsigned long carries;
  202.   int bm;
  203.   long_long uu;
  204.   int b = b1;
  205.  
  206.   if (b == 0)
  207.     return u;
  208.  
  209.   uu.ll = u;
  210.  
  211.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  212.   if (bm <= 0)
  213.     {
  214.       w.s.low = 0;
  215.       w.s.high = (unsigned long)uu.s.low << -bm;
  216.     }
  217.   else
  218.     {
  219.       carries = (unsigned long)uu.s.low >> bm;
  220.       w.s.low = (unsigned long)uu.s.low << b;
  221.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  222.     }
  223.  
  224.   return w.ll;
  225. }
  226. #endif
  227.  
  228. #ifdef L_lshrdi3
  229. long long
  230. __lshrdi3 (u, b1)
  231.      long long u;
  232.      long long b1;
  233. {
  234.   long_long w;
  235.   unsigned long carries;
  236.   int bm;
  237.   long_long uu;
  238.   int b = b1;
  239.  
  240.   if (b == 0)
  241.     return u;
  242.  
  243.   uu.ll = u;
  244.  
  245.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  246.   if (bm <= 0)
  247.     {
  248.       w.s.high = 0;
  249.       w.s.low = (unsigned long)uu.s.high >> -bm;
  250.     }
  251.   else
  252.     {
  253.       carries = (unsigned long)uu.s.high << bm;
  254.       w.s.high = (unsigned long)uu.s.high >> b;
  255.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  256.     }
  257.  
  258.   return w.ll;
  259. }
  260. #endif
  261.  
  262. #ifdef L_ashldi3
  263. long long
  264. __ashldi3 (u, b1)
  265.      long long u;
  266.      long long b1;
  267. {
  268.   long_long w;
  269.   unsigned long carries;
  270.   int bm;
  271.   long_long uu;
  272.   int b = b1;
  273.  
  274.   if (b == 0)
  275.     return u;
  276.  
  277.   uu.ll = u;
  278.  
  279.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  280.   if (bm <= 0)
  281.     {
  282.       w.s.low = 0;
  283.       w.s.high = (unsigned long)uu.s.low << -bm;
  284.     }
  285.   else
  286.     {
  287.       carries = (unsigned long)uu.s.low >> bm;
  288.       w.s.low = (unsigned long)uu.s.low << b;
  289.       w.s.high = ((unsigned long)uu.s.high << b) | carries;
  290.     }
  291.  
  292.   return w.ll;
  293. }
  294. #endif
  295.  
  296. #ifdef L_ashrdi3
  297. long long
  298. __ashrdi3 (u, b1)
  299.      long long u;
  300.      long long b1;
  301. {
  302.   long_long w;
  303.   unsigned long carries;
  304.   int bm;
  305.   long_long uu;
  306.   int b = b1;
  307.  
  308.   if (b == 0)
  309.     return u;
  310.  
  311.   uu.ll = u;
  312.  
  313.   bm = (sizeof (int) * BITS_PER_UNIT) - b;
  314.   if (bm <= 0)
  315.     {
  316.       w.s.high = uu.s.high >> 31; /* just to make w.s.high 1..1 or 0..0 */
  317.       w.s.low = uu.s.high >> -bm;
  318.     }
  319.   else
  320.     {
  321.       carries = (unsigned long)uu.s.high << bm;
  322.       w.s.high = uu.s.high >> b;
  323.       w.s.low = ((unsigned long)uu.s.low >> b) | carries;
  324.     }
  325.  
  326.   return w.ll;
  327. }
  328. #endif
  329.  
  330. #ifdef L_subdi3
  331. long long 
  332. __subdi3 (u, v)
  333.      long long u, v;
  334. {
  335.   long a[2], b[2], c[2];
  336.   long_long w;
  337.   long_long uu, vv;
  338.  
  339.   uu.ll = u;
  340.   vv.ll = v;
  341.  
  342.   a[HIGH] = uu.s.high;
  343.   a[LOW] = uu.s.low;
  344.   b[HIGH] = vv.s.high;
  345.   b[LOW] = vv.s.low;
  346.  
  347.   bsub (a, b, c, sizeof c);
  348.  
  349.   w.s.high = c[HIGH];
  350.   w.s.low = c[LOW];
  351.   return w.ll;
  352. }
  353.  
  354. static int 
  355. bsub (a, b, c, n)
  356.      unsigned short *a, *b, *c;
  357.      size_t n;
  358. {
  359.   signed long acc;
  360.   int i;
  361.  
  362.   n /= sizeof *c;
  363.  
  364.   acc = 0;
  365.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  366.     {
  367.       /* Widen before subtracting to avoid loss of high bits.  */
  368.       acc += (long) a[i] - b[i];
  369.       c[i] = acc & low16;
  370.       acc = acc >> 16;
  371.     }
  372.   return acc;
  373. }
  374. #endif
  375.  
  376. #ifdef L_muldi3
  377. long long 
  378. __muldi3 (u, v)
  379.      long long u, v;
  380. {
  381.   long a[2], b[2], c[2][2];
  382.   long_long w;
  383.   long_long uu, vv;
  384.  
  385.   uu.ll = u;
  386.   vv.ll = v;
  387.  
  388.   a[HIGH] = uu.s.high;
  389.   a[LOW] = uu.s.low;
  390.   b[HIGH] = vv.s.high;
  391.   b[LOW] = vv.s.low;
  392.  
  393.   bmul (a, b, c, sizeof a, sizeof b);
  394.  
  395.   w.s.high = c[LOW][HIGH];
  396.   w.s.low = c[LOW][LOW];
  397.   return w.ll;
  398. }
  399.  
  400. static void 
  401. bmul (a, b, c, m, n)
  402.     unsigned short *a, *b, *c;
  403.     size_t m, n;
  404. {
  405.   int i, j;
  406.   unsigned long acc;
  407.  
  408.   bzero (c, m + n);
  409.  
  410.   m /= sizeof *a;
  411.   n /= sizeof *b;
  412.  
  413.   for (j = little_end (n); is_not_msd (j, n); j = next_msd (j))
  414.     {
  415.       unsigned short *c1 = c + j + little_end (2);
  416.       acc = 0;
  417.       for (i = little_end (m); is_not_msd (i, m); i = next_msd (i))
  418.     {
  419.       /* Widen before arithmetic to avoid loss of high bits.  */
  420.       acc += (unsigned long) a[i] * b[j] + c1[i];
  421.       c1[i] = acc & low16;
  422.       acc = acc >> 16;
  423.     }
  424.       c1[i] = acc;
  425.     }
  426. }
  427. #endif
  428.  
  429. #ifdef L_divdi3
  430. long long
  431. __divdi3 (u, v)
  432.      long long u, v;
  433. {
  434.   if (u < 0)
  435.     if (v < 0)
  436.       return (unsigned long long) -u / (unsigned long long) -v;
  437.     else
  438.       return - ((unsigned long long) -u / (unsigned long long) v);
  439.   else
  440.     if (v < 0)
  441.       return - ((unsigned long long) u / (unsigned long long) -v);
  442.     else
  443.       return (unsigned long long) u / (unsigned long long) v;
  444. }
  445. #endif
  446.  
  447. #ifdef L_moddi3
  448. long long
  449. __moddi3 (u, v)
  450.      long long u, v;
  451. {
  452.   if (u < 0)
  453.     if (v < 0)
  454.       return - ((unsigned long long) -u % (unsigned long long) -v);
  455.     else
  456.       return - ((unsigned long long) -u % (unsigned long long) v);
  457.   else
  458.     if (v < 0)
  459.       return (unsigned long long) u % (unsigned long long) -v;
  460.     else
  461.       return (unsigned long long) u % (unsigned long long) v;
  462. }
  463. #endif
  464.  
  465. #ifdef L_udivdi3
  466. long long 
  467. __udivdi3 (u, v)
  468.      long long u, v;
  469. {
  470.   unsigned long a[2][2], b[2], q[2], r[2];
  471.   long_long w;
  472.   long_long uu, vv;
  473.  
  474.   uu.ll = u;
  475.   vv.ll = v;
  476.  
  477.   a[HIGH][HIGH] = 0;
  478.   a[HIGH][LOW] = 0;
  479.   a[LOW][HIGH] = uu.s.high;
  480.   a[LOW][LOW] = uu.s.low;
  481.   b[HIGH] = vv.s.high;
  482.   b[LOW] = vv.s.low;
  483.  
  484.   __bdiv (a, b, q, r, sizeof a, sizeof b);
  485.  
  486.   w.s.high = q[HIGH];
  487.   w.s.low = q[LOW];
  488.   return w.ll;
  489. }
  490. #endif
  491.  
  492. #ifdef L_umoddi3
  493. long long 
  494. __umoddi3 (u, v)
  495.      long long u, v;
  496. {
  497.   unsigned long a[2][2], b[2], q[2], r[2];
  498.   long_long w;
  499.   long_long uu, vv;
  500.  
  501.   uu.ll = u;
  502.   vv.ll = v;
  503.  
  504.   a[HIGH][HIGH] = 0;
  505.   a[HIGH][LOW] = 0;
  506.   a[LOW][HIGH] = uu.s.high;
  507.   a[LOW][LOW] = uu.s.low;
  508.   b[HIGH] = vv.s.high;
  509.   b[LOW] = vv.s.low;
  510.  
  511.   __bdiv (a, b, q, r, sizeof a, sizeof b);
  512.  
  513.   w.s.high = r[HIGH];
  514.   w.s.low = r[LOW];
  515.   return w.ll;
  516. }
  517. #endif
  518.  
  519. #ifdef L_negdi2
  520. long long 
  521. __negdi2 (u)
  522.      long long u;
  523. {
  524.   unsigned long a[2], b[2];
  525.   long_long w;
  526.   long_long uu;
  527.  
  528.   uu.ll = u;
  529.  
  530.   a[HIGH] = uu.s.high;
  531.   a[LOW] = uu.s.low;
  532.  
  533.   bneg (a, b, sizeof b);
  534.  
  535.   w.s.high = b[HIGH];
  536.   w.s.low = b[LOW];
  537.   return w.ll;
  538. }
  539.  
  540. static int
  541. bneg (a, b, n)
  542.      unsigned short *a, *b;
  543.      size_t n;
  544. {
  545.   signed long acc;
  546.   int i;
  547.  
  548.   n /= sizeof (short);
  549.  
  550.   acc = 0;
  551.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  552.     {
  553.       acc -= a[i];
  554.       b[i] = acc & low16;
  555.       acc = acc >> 16;
  556.     }
  557.   return acc;
  558. }
  559. #endif
  560.  
  561. /* Divide a by b, producing quotient q and remainder r.
  562.  
  563.        sizeof a is m
  564.        sizeof b is n
  565.        sizeof q is m - n
  566.        sizeof r is n
  567.  
  568.    The quotient must fit in m - n bytes, i.e., the most significant
  569.    n digits of a must be less than b, and m must be greater than n.  */
  570.  
  571. /* The name of this used to be __div_internal,
  572.    but that is too long for SYSV.  */
  573.  
  574. #ifdef L_bdiv
  575. void 
  576. __bdiv (a, b, q, r, m, n)
  577.      unsigned short *a, *b, *q, *r;
  578.      size_t m, n;
  579. {
  580.   unsigned long qhat, rhat;
  581.   unsigned long acc;
  582.   unsigned short *u = (unsigned short *) alloca (m);
  583.   unsigned short *v = (unsigned short *) alloca (n);
  584.   unsigned short *u0, *u1, *u2;
  585.   unsigned short *v0;
  586.   int d, qn;
  587.   int i, j;
  588.  
  589.   m /= sizeof *a;
  590.   n /= sizeof *b;
  591.   qn = m - n;
  592.  
  593.   /* Remove leading zero digits from divisor, and the same number of
  594.      digits (which must be zero) from dividend.  */
  595.  
  596.   while (b[big_end (n)] == 0)
  597.     {
  598.       r[big_end (n)] = 0;
  599.  
  600.       a += little_end (2);
  601.       b += little_end (2);
  602.       r += little_end (2);
  603.       m--;
  604.       n--;
  605.  
  606.       /* Check for zero divisor.  */
  607.       if (n == 0)
  608.     abort ();
  609.     }
  610.       
  611.   /* If divisor is a single digit, do short division.  */
  612.  
  613.   if (n == 1)
  614.     {
  615.       acc = a[big_end (m)];
  616.       a += little_end (2);
  617.       for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  618.     {
  619.       acc = (acc << 16) | a[j];
  620.       q[j] = acc / *b;
  621.       acc = acc % *b;
  622.     }
  623.       *r = acc;
  624.       return;
  625.     }
  626.  
  627.   /* No such luck, must do long division. Shift divisor and dividend
  628.      left until the high bit of the divisor is 1.  */
  629.  
  630.   for (d = 0; d < 16; d++)
  631.     if (b[big_end (n)] & (1 << (16 - 1 - d)))
  632.       break;
  633.  
  634.   bshift (a, d, u, 0, m);
  635.   bshift (b, d, v, 0, n);
  636.  
  637.   /* Get pointers to the high dividend and divisor digits.  */
  638.  
  639.   u0 = u + big_end (m) - big_end (qn);
  640.   u1 = next_lsd (u0);
  641.   u2 = next_lsd (u1);
  642.   u += little_end (2);
  643.  
  644.   v0 = v + big_end (n);
  645.  
  646.   /* Main loop: find a quotient digit, multiply it by the divisor,
  647.      and subtract that from the dividend, shifted over the right amount. */
  648.  
  649.   for (j = big_end (qn); is_not_lsd (j, qn); j = next_lsd (j))
  650.     {
  651.       /* Quotient digit initial guess: high 2 dividend digits over high
  652.      divisor digit.  */
  653.  
  654.       if (u0[j] == *v0)
  655.     {
  656.       qhat = B - 1;
  657.       rhat = (unsigned long) *v0 + u1[j];
  658.     }
  659.       else
  660.     {
  661.       unsigned long numerator = ((unsigned long) u0[j] << 16) | u1[j];
  662.       qhat = numerator / *v0;
  663.       rhat = numerator % *v0;
  664.     }
  665.  
  666.       /* Now get the quotient right for high 3 dividend digits over
  667.      high 2 divisor digits.  */
  668.  
  669.       while (rhat < B && qhat * *next_lsd (v0) > ((rhat << 16) | u2[j]))
  670.     {
  671.       qhat -= 1;
  672.       rhat += *v0;
  673.     }
  674.         
  675.       /* Multiply quotient by divisor, subtract from dividend.  */
  676.  
  677.       acc = 0;
  678.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  679.     {
  680.       acc += (unsigned long) (u + j)[i] - v[i] * qhat;
  681.       (u + j)[i] = acc & low16;
  682.       if (acc < B)
  683.         acc = 0;
  684.       else
  685.         acc = (acc >> 16) | -B;
  686.     }
  687.  
  688.       q[j] = qhat;
  689.  
  690.       /* Quotient may have been too high by 1.  If dividend went negative,
  691.      decrement the quotient by 1 and add the divisor back.  */
  692.  
  693.       if ((signed long) (acc + u0[j]) < 0)
  694.     {
  695.       q[j] -= 1;
  696.       acc = 0;
  697.       for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  698.         {
  699.           acc += (unsigned long) (u + j)[i] + v[i];
  700.           (u + j)[i] = acc & low16;
  701.           acc = acc >> 16;
  702.         }
  703.     }
  704.     }
  705.  
  706.   /* Now the remainder is what's left of the dividend, shifted right
  707.      by the amount of the normalizing left shift at the top.  */
  708.  
  709.   r[big_end (n)] = bshift (u + 1 + little_end (j - 1),
  710.                16 - d,
  711.                r + little_end (2),
  712.                u[little_end (m - 1)] >> d,
  713.                n - 1);
  714. }
  715.  
  716. /* Left shift U by K giving W; fill the introduced low-order bits with
  717.    CARRY_IN.  Length of U and W is N.  Return carry out.  K must be
  718.    in 0 .. 16.  */
  719.  
  720. static int
  721. bshift (u, k, w, carry_in, n)
  722.      unsigned short *u, *w, carry_in;
  723.      int k, n;
  724. {
  725.   unsigned long acc;
  726.   int i;
  727.  
  728.   if (k == 0)
  729.     {
  730.       bcopy (u, w, n * sizeof *u);
  731.       return 0;
  732.     }
  733.  
  734.   acc = carry_in;
  735.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  736.     {
  737.       acc |= (unsigned long) u[i] << k;
  738.       w[i] = acc & low16;
  739.       acc = acc >> 16;
  740.     }
  741.   return acc;
  742. }
  743. #endif
  744.  
  745. #ifdef L_cmpdi2
  746. SItype
  747. __cmpdi2 (a, b)
  748.      long long a, b;
  749. {
  750.   long_long au, bu;
  751.  
  752.   au.ll = a, bu.ll = b;
  753.  
  754.   if (au.s.high < bu.s.high)
  755.     return 0;
  756.   else if (au.s.high > bu.s.high)
  757.     return 2;
  758.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  759.     return 0;
  760.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  761.     return 2;
  762.   return 1;
  763. }
  764. #endif
  765.  
  766. #ifdef L_ucmpdi2
  767. SItype
  768. __ucmpdi2 (a, b)
  769.      long long a, b;
  770. {
  771.   long_long au, bu;
  772.  
  773.   au.ll = a, bu.ll = b;
  774.  
  775.   if ((unsigned) au.s.high < (unsigned) bu.s.high)
  776.     return 0;
  777.   else if ((unsigned) au.s.high > (unsigned) bu.s.high)
  778.     return 2;
  779.   if ((unsigned) au.s.low < (unsigned) bu.s.low)
  780.     return 0;
  781.   else if ((unsigned) au.s.low > (unsigned) bu.s.low)
  782.     return 2;
  783.   return 1;
  784. }
  785. #endif
  786.  
  787. #ifdef L_fixunsdfdi
  788. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  789.  
  790. long long
  791. __fixunsdfdi (a)
  792.      double a;
  793. {
  794.   double b;
  795.   unsigned long long v;
  796.  
  797.   if (a < 0)
  798.     return 0;
  799.  
  800.   /* Compute high word of result, as a flonum.  */
  801.   b = (a / HIGH_WORD_COEFF);
  802.   /* Convert that to fixed (but not to long long!),
  803.      and shift it into the high word.  */
  804.   v = (unsigned long int) b;
  805.   v <<= BITS_PER_WORD;
  806.   /* Remove high part from the double, leaving the low part as flonum.  */
  807.   a -= (double)v;
  808.   /* Convert that to fixed (but not to long long!) and add it in.
  809.      Sometimes A comes out negative.  This is significant, since
  810.      A has more bits than a long int does.  */
  811.   if (a < 0)
  812.     v -= (unsigned long int) (- a);
  813.   else
  814.     v += (unsigned long int) a;
  815.   return v;
  816. }
  817. #endif
  818.  
  819. #ifdef L_fixdfdi
  820. long long
  821. __fixdfdi (a)
  822.      double a;
  823. {
  824.   long long __fixunsdfdi (double a);
  825.  
  826.   if (a < 0)
  827.     return - __fixunsdfdi (-a);
  828.   return __fixunsdfdi (a);
  829. }
  830. #endif
  831.  
  832. #ifdef L_floatdidf
  833. #define HIGH_HALFWORD_COEFF (((long long) 1) << (BITS_PER_WORD / 2))
  834. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  835.  
  836. double
  837. __floatdidf (u)
  838.      long long u;
  839. {
  840.   double d;
  841.   int negate = 0;
  842.  
  843.   if (d < 0)
  844.     u = -u, negate = 1;
  845.  
  846.   d = (unsigned int) (u >> BITS_PER_WORD);
  847.   d *= HIGH_HALFWORD_COEFF;
  848.   d *= HIGH_HALFWORD_COEFF;
  849.   d += (unsigned int) (u & (HIGH_WORD_COEFF - 1));
  850.  
  851.   return (negate ? -d : d);
  852. }
  853. #endif
  854.  
  855. #ifdef L_varargs
  856. #ifdef sparc
  857.     asm (".global ___builtin_saveregs");
  858.     asm ("___builtin_saveregs:");
  859.     asm ("st %i0,[%fp+68]");
  860.     asm ("st %i1,[%fp+72]");
  861.     asm ("st %i2,[%fp+76]");
  862.     asm ("st %i3,[%fp+80]");
  863.     asm ("st %i4,[%fp+84]");
  864.     asm ("retl");
  865.     asm ("st %i5,[%fp+88]");
  866. #else /* not sparc */
  867. #if defined(MIPSEL) | defined(R3000) | defined(R2000) | defined(mips)
  868.  
  869.   asm ("    .ent __builtin_saveregs");
  870.   asm ("    .globl __builtin_saveregs");
  871.   asm ("__builtin_saveregs:");
  872.   asm ("    sw    $4,0($30)");
  873.   asm ("    sw    $5,4($30)");
  874.   asm ("    sw    $6,8($30)");
  875.   asm ("    sw    $7,12($30)");
  876.   asm ("    j    $31");
  877.   asm ("    .end __builtin_saveregs");
  878. #else /* not mips */
  879. __builtin_saveregs ()
  880. {
  881.   abort ();
  882. }
  883. #endif /* not mips */
  884. #endif /* not sparc */
  885. #endif
  886.